package com.swinw.asumall.order.controller;

import com.alibaba.fastjson.JSON;
import com.swinw.asumall.order.entity.OrderEntity;
import com.swinw.asumall.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@RestController
public class RabbitController {

    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/message")
    public String message(Integer num){
        for(int i = 0;i < num ;i++){
            if(i % 2 ==0){
                OrderReturnReasonEntity entity = new OrderReturnReasonEntity();
                entity.setId(100L);
                entity.setCreateTime(new Date());
                entity.setName("haha");
                entity.setSort(0);
                entity.setStatus(1);
                rabbitTemplate.convertAndSend("hello_java",
                        "hello.java",
                        entity);
            }else{
                OrderEntity entity = new OrderEntity();
                entity.setId(100L);
                entity.setCreateTime(new Date());
                entity.setOrderSn(UUID.randomUUID().toString());
                rabbitTemplate.convertAndSend("hello_java",
                        "hello.java",
                        entity);
            }
        }
        return "发送完成";
    }

}
